package com.camel.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.camel.auth.mapper.SysRoleMapper;
import com.camel.auth.mapper.SysUserMapper;
import com.camel.auth.model.SysUser;
import com.camel.auth.service.ISysUserService;
import com.camel.core.model.SysRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 用户信息表 服务实现类
 * </p>
 *
 * @author camel
 * @since 2022-11-09
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {

    @Autowired
    private SysUserMapper userMapper;

    @Autowired
    private SysRoleMapper roleMapper;

    @Override
    public List<String> selectUserMenu(Integer uid) {
        return userMapper.selectUserMenu(uid) ;
    }

    @Override
    public List<String> selectUserRole(Integer uid) {
        return userMapper.selectUserRole(uid);
    }

    @Override
    public List<String> selectRootMenu() {
        return userMapper.selectRootMenu();
    }

    @Override
    public SysUser getById(Serializable id) {
        SysUser u = super.getById(id);
        SysRole role = roleMapper.selectOne(new QueryWrapper<SysRole>().eq("role_name", u.getRoleName()));
        if(ObjectUtils.isEmpty(role)) {
            return u;
        }
        u.setRoleNameCN(role.getRemark());
        return u;
    }
}
